package com.atguigu.yygh.hosp.controller.user;

import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.result.R;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/3/18 21:16
 */
@Api(tags = "医院用户接口")
@RestController
@RequestMapping("user/hosp")
public class HospitalUserController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private DepartmentService departmentService;
    @GetMapping("/list/{page}/{limit}")
    public R index(@PathVariable("page") Integer page,
                   @PathVariable("limit") Integer limit,
                    HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitals = hospitalService.selectPage(page, limit,hospitalQueryVo);
        return R.ok().data("list", hospitals.getContent()).data("total", hospitals.getTotalElements());
    }
    //根据医院名称模糊查询
    @GetMapping("/search/{hosname}")
    public R search(@PathVariable("hosname") String hosname) {
        List<Hospital> list = hospitalService.selectByNameLike(hosname);
        return R.ok().data("list", list);
    }
    //根据hoscode获取科室列表
    @GetMapping("/depts/{hoscode}")
    public R depts(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> deptList = departmentService.getDeptList(hoscode);
        return R.ok().data("list", deptList);
    }


    //根据hoscode获取医院详情
    @GetMapping("/detail/{hoscode}")
    public R detail(@PathVariable("hoscode") String hoscode) {
        Hospital hospital=hospitalService.findHospitalByHoscode(hoscode);
        return R.ok().data("hospital", hospital);
    }
}
